package com.hhkj.api.common.common.sms;

import cn.hutool.extra.spring.SpringUtil;
import com.hhkj.api.common.common.cont.SaleCaptchaTypeEnum;
import com.hhkj.sms.common.template.AliDaYuTemplate;
import com.ruoyi.common.exception.GlobalException;
import lombok.AllArgsConstructor;
import lombok.Getter;

/**
 * SaleCaptchaTemplateEnum
 *
 * @author HHKJ-SERVER-ZJ
 * @since 2023/10/25 12:07
 */
@Getter
@AllArgsConstructor
public enum SaleCaptchaTemplateEnum {
    REGISTER(SaleCaptchaTypeEnum.REGISTER.getCode(),
            new AliDaYuTemplate("虹合科技", "SMS_142386989"),
            new AliDaYuTemplate("毅诚教育", "SMS_142386989")
    ),
    RESET_PASSWORD(SaleCaptchaTypeEnum.RESET_PASSWORD.getCode(),
            new AliDaYuTemplate("虹合科技", "SMS_142386989"),
            new AliDaYuTemplate("毅诚教育", "SMS_142386989")
    ),
    UPDATE_PASSWORD(SaleCaptchaTypeEnum.UPDATE_PASSWORD.getCode(),
            new AliDaYuTemplate("虹合科技", "SMS_142386989"),
            new AliDaYuTemplate("毅诚教育", "SMS_142386989")
    ),
    REGISTER_STUDENT(SaleCaptchaTypeEnum.REGISTER_STUDENT.getCode(),
            new AliDaYuTemplate("虹合科技", "SMS_142386989"),
            new AliDaYuTemplate("毅诚教育", "SMS_142386989")
    ),
    ;

    /** 编码 */
    private final String code;

    /** 模板 */
    private final AliDaYuTemplate template;

    /** 浙建学堂模板 */
    private final AliDaYuTemplate smsProTemplate;

    public static AliDaYuTemplate getTemplate(String code) {
        for (SaleCaptchaTemplateEnum templateEnum : values()) {
            if (templateEnum.code.equals(code)) {
                String activeProfile = SpringUtil.getActiveProfile();
                return
                        "sms-pro".equals(activeProfile) ? templateEnum.getSmsProTemplate() : templateEnum.getTemplate();
            }
        }
        throw new GlobalException("无对应短信模板，请联系管理员");
    }
}
